﻿using MediatR;
using RBAC.Api.Demain.Entities;
using RBAC.Api.Erroc;
using RBAC.Api.Infaction;
using RBAC.Api.Read.Command.RBAC;

namespace RBAC.Api.Read.CommandHandler.RBAC
{
    public class PermissionQueryCommandHandler : IRequestHandler<PermissionQueryCommand, APIResult<List<Permission>>>
    {
        private readonly IBaseRepositry<Permission> baseRepositry;

        public PermissionQueryCommandHandler(IBaseRepositry<Permission> baseRepositry)
        {
            this.baseRepositry = baseRepositry;
        }
        public Task<APIResult<List<Permission>>> Handle(PermissionQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Permission>> result = new APIResult<List<Permission>>();
            result.Code = ResultCode.Success;
            result.Message = "查询成功";

            var list = baseRepositry.GetAll().ToList();

            result.Data = list;

            return Task.FromResult(result);
        }
    }
}
